package com.application;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.application.databinding.ActivityLoginBinding;
import com.application.databinding.ActivityMainBinding;
import com.application.util.ARouterConstants;

@Route(path = ARouterConstants.ACTIVITY_URL_MAIN)
public class MainActivity extends AppCompatActivity {
    // ##################################################################
    // 旧代码：已废弃，用注释包裹，不参与编译（保留仅作参考）新代码在MainFragmentActivity
    // ##################################################################
    private ActivityMainBinding binding;

    private static final String TAG = "tag";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate: -------------------");
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        binding.setMain(this);
        binding.setLifecycleOwner(this);
        binding.tvSignature.setSelected(true);
        binding.buttonChange.setOnClickListener(v -> {
            binding.tvSignature.setText("像风翻书一样翻过大好时光，每一页都藏着不期而遇的光");
            Toast.makeText(MainActivity.this, "更换签名成功!", Toast.LENGTH_SHORT).show();
        });

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            String login_username = bundle.getString("username");
            Toast.makeText(this, "欢迎 " + login_username + " 登录", Toast.LENGTH_LONG).show();
        }

    }

    public void jumpToEvaluation(View view) {
        ARouter.getInstance()
                .build(ARouterConstants.ACTIVITY_URL_EVALUATION)
                .navigation(this);
    }

    public void jumpToHandler(View view) {
        ARouter.getInstance()
                .build(ARouterConstants.ACTIVITY_URL_HANDLER)
                .navigation(this);
    }

    public void jumpToRetrofitRxJava(View view) {
        ARouter.getInstance()
                .build(ARouterConstants.ACTIVITY_URL_RETROFIT_BY_JAVA)
                .navigation(this);
    }

    public void jumpToLiveEventBus(View view) {
        ARouter.getInstance()
                .build(ARouterConstants.ACTIVITY_URL_LIVE_EVENT_BUS)
                .navigation(this);
    }

    public void jumpToRecyclerView(View view) {
        ARouter.getInstance()
                .build(ARouterConstants.ACTIVITY_URL_RECYCLER_VIEW)
                .navigation(this);
    }
}

